// These 2 expansions are needed to make sure that everything is concatenated correctly.
#define Concat_Expansion2(x, y)	x##y
#define Concat_Expansion1(x, y) Concat_Expansion2(x, y)
#define Concat(x, y)			Concat_Expansion1(x, y)

// Sets up the CreateControl function and the factory switch.
#define StartWidgetTypes(_Next)											\
	Concat(																\
		{																\
			switch(_WidgetType)											\
			{															\
			default:													\
				Error("Invalid widget type specified.\n");				\
				return NULL;											\
			case Widget::Type::Widget:									\
				Error("Ordinary Widgets cannot be instantiated.\n");	\
				return NULL;											\
	, _Next)


// Creates a case statement for the type, creates a factory function and inserts _Func into that.
#define AddWidgetType(_Type, _Func, _Next)								\
	Concat(																\
		case Widget::Type::##_Type:										\
			return WidgetFactory::_Create##_Type(_Parent);				\
	, _Next)															\
	_AddWidgetCreateFunc(_Type, _Func)

// Closes the factory switch.
#define EndWidgetTypes()												\
		};																\
	}

// Creates a factory function for the type and inserts _Func
#define _AddWidgetCreateFunc(_Type, _Func)								\
private:																\
	static Widget* _Create##_Type(Control* _Parent)						\
	{																	\
		Widgets::##_Type* obj = new Widgets::##_Type(_Parent);			\
		_Func															\
		return obj;														\
	}																	//\
//	static Widgets::##_Type##Vector m_##_Type##s;						\
//	static Widgets::##_Type##Vector Get##_Type##s()						\
//	{	return m_##_Type##s;;	}									